package com.gupao.study.autoconfiguration;

import com.gupao.study.formater.FormateProcessor;
import com.gupao.study.formater.JsonFormatProcessor;
import com.gupao.study.formater.StringFormatProcessor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * @author wangenji
 * @Date 2019-07-07 13:35
 */
@Configuration
public class ProcessorConfiguration {

    @Bean
    @ConditionalOnClass(name = "com.alibaba.fastjson.JSON")
    public FormateProcessor jsonFormatProcessor(){
        return new JsonFormatProcessor();
    }


    @Bean
    @Primary
    @ConditionalOnMissingClass("com.alibaba.fastjson.JSON")
    public FormateProcessor stringFormatProcessor(){
        return new StringFormatProcessor();
    }
}
